import type { User } from "@/api/user/type";

// 对于token存储和读取
const TOKEN_KEY = 'TOKEN';
const THEME = 'THEME';

const SET_TOKEN = (token: string) => {
    localStorage.setItem(TOKEN_KEY, token)
}

const GET_TOKEN = () => {
    return localStorage.getItem(TOKEN_KEY)
}

const USER_INFO = 'USER_INFO';

const SET_USER_INFO = (userInfo: User | null) => {
    localStorage.setItem(USER_INFO, JSON.stringify(userInfo))
}

const GET_USER_INFO = (): User | null => {
    return JSON.parse(localStorage.getItem(USER_INFO) as string) as User
}

const RESET = () => {
    localStorage.removeItem(TOKEN_KEY)
    localStorage.removeItem(USER_INFO)
}

const SET_THEME = (theme: string) => {
    localStorage.setItem(THEME, JSON.stringify(theme))
}

const GET_THEME = (): string | null => {
    return JSON.parse(localStorage.getItem(THEME) as string) as string
}

export { SET_TOKEN, GET_TOKEN, SET_USER_INFO, GET_USER_INFO, RESET, SET_THEME, GET_THEME }